﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BoAddonBiz_FreightForwarder.Cost.Bill_Draft
{
    class B1Form_BillDraft : SAPBoAddon.B1Form
    {
        #region variable
        BillDraft oBillDraft;
        Bo.OrderType Type;
        bool AddBill = false;
        #endregion
        #region Constractor
        public B1Form_BillDraft()
        {
            AddBill = false;
            this.frm_ItemEvent += new SAPBoAddon.IB1FormEvents.B1ItemEventEventHandler(B1Form_BillDraft_frm_ItemEvent);
            this.frm_ChooseFormListEvent += new SAPBoAddon.IB1FormEvents.B1ChooseFormListEventEventHandler(B1Form_BillDraft_frm_ChooseFormListEvent);
        }
        #endregion
        #region override
        protected override bool BeforeSaveCheckFormData()
        {
            return true;
        }

        protected override void FormEditModeChange(SAPBoAddon.frmItemEditMode frmEditMode)
        {

        }

        protected override void FormInfoSetting(SAPBoAddon.B1FormSetting FormSetting)
        {
            this.FormSetting.FormType = B1FormTypes.ado_AVA_BillDraft;
            this.FormSetting.FormFileName = B1FormTypes.ado_AVA_BillDraft + "Form.srf";
        }

        protected override void InitializeForm(SAPBoAddon.B1FormInitializePar InitPar)
        {
            AddBill = false;
            oBillDraft = null;
            //应收
            if (InitPar.KeyValue == B1MenuTypes.ado_AVA_BillDraft_AR)
            {
                Type = Bo.OrderType.ARInvoice;
                CurrentForm.Title = "应收 " + CurrentForm.Title;
            }
            //应付
            if (InitPar.KeyValue == B1MenuTypes.ado_AVA_BillDraft_AP)
            {
                Type = Bo.OrderType.APInvoice;
                CurrentForm.Title = "应付 " + CurrentForm.Title;
            }
            Utils.InitialItemComboBox(SBOCompany, this.CurrentForm.Items.Item("DocCurr"), "CurrCode", "CurrName", "OCRN", null, "RMB");//费用币种
        }
        #endregion
        #region events
        void B1Form_BillDraft_frm_ItemEvent(SAPBoAddon.B1AddonBase.B1ItemEvent pVal, ref bool BubbleEvent)
        {
            if (pVal.BeforeAction)
            {
                if (pVal.ItemUID == "1" && pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED)
                {
                    if (CurrentForm.Mode == SAPbouiCOM.BoFormMode.fm_UPDATE_MODE)
                        CreateDraft(ref BubbleEvent);
                }
            }
            else
            {
                if (pVal.ItemUID == "Find" && pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED)
                {
                    Find();
                }
                if (pVal.ItemUID == "AddBill" && pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED)
                {
                    SAPBoAddon.B1Assistant.Item.SetEnabled(CurrentForm, "StartDate", true);
                    SAPBoAddon.B1Assistant.Item.SetEnabled(CurrentForm, "EndDate", true);
                    SAPBoAddon.B1Assistant.Item.SetEnabled(CurrentForm, "Currency", true);
                    SAPBoAddon.B1Assistant.Item.SetEnabled(CurrentForm, "rdooBill", true);
                    SAPBoAddon.B1Assistant.Item.SetEnabled(CurrentForm, "rdooFee", true);
                    SAPBoAddon.B1Assistant.Item.SetEnabled(CurrentForm, "rdooAll", true);
                    SAPbouiCOM.EditText oedit = CurrentForm.Items.Item("StartDate").Specific;
                    oedit.Active = true;
                    if (oBillDraft != null)
                    {
                        SAPBoAddon.B1Assistant.Item.SetValue(pVal.FormUID, "CardName", oBillDraft.CardName);
                        AddBill = true;
                    }
                }
                //控件值发生变化
                if (pVal.ItemUID == "Grid" && pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED)
                {
                    //grid
                    if (pVal.ColUID != null && pVal.Row >= 0 && pVal.ColUID == "Choose")
                    {
                        UIChanged(pVal.ItemUID, pVal.ColUID, pVal.Row);
                    }
                }
                if (pVal.ItemUID == "Grid" && pVal.Row == -1 && pVal.EventType == SAPbouiCOM.BoEventTypes.et_DOUBLE_CLICK)
                {

                    SAPbouiCOM.Grid grid = this.CurrentForm.Items.Item("Grid").Specific;
                    if (!String.IsNullOrEmpty(pVal.ColUID))
                        Utils.ReSort(grid, pVal.ColUID);//排序
                }
                if ((pVal.ItemUID == "rdobill" || pVal.ItemUID == "rdoitem") && (pVal.ItemChanged || pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED))
                {
                    IsBill(pVal.ItemUID);
                }
                //全选 
                if (pVal.ItemUID == "btnAll" && pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED)
                {
                    ChooseOrder(true);
                }
                //全不选 
                if (pVal.ItemUID == "btnNo" && pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED)
                {
                    ChooseOrder(false);
                }
                //反选 
                if (pVal.ItemUID == "btnAb" && pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED)
                {
                    ChooseAbOrder();
                }
                if (pVal.ItemUID == "DocCurr" && pVal.EventType == SAPbouiCOM.BoEventTypes.et_COMBO_SELECT)
                {
                    string Currency = CurrentForm.DataSources.UserDataSources.Item("DocCurr").Value.Trim();
                    decimal rate = Utils.GetRateByCurrency(Currency);
                    CurrentForm.DataSources.UserDataSources.Item("DocRate").Value = rate.ToString();
                    if (oBillDraft != null)
                    {
                        oBillDraft.Currency = Currency;
                        oBillDraft.Rate = Convert.ToDouble(rate);
                    }
                }
            }
        }

        void B1Form_BillDraft_frm_ChooseFormListEvent(SAPBoAddon.B1AddonBase.B1ChooseFormList pVal, ref bool BubbleEvent)
        {
            if (pVal.Before_Action)
            {
                SAPbouiCOM.ChooseFromList cfl = this.CurrentForm.ChooseFromLists.Item(pVal.ChooseFromListUID);
                SAPbouiCOM.Conditions cons;
                SAPbouiCOM.Condition con;
                switch (pVal.ChooseFromListUID)
                {
                    case "CFL_OCRD"://目的港代理
                        cons = new SAPbouiCOM.Conditions();
                        con = cons.Add();
                        con.Alias = "CardType";
                        if (Type == Bo.OrderType.ARInvoice)
                            con.CondVal = "C";
                        else
                            con.CondVal = "S";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        cfl.SetConditions(cons);
                        break;
                }
            }
            else
            {
                if (pVal.Action_Success)
                {
                    if (pVal.ChooseFromListUID == "CFL_OCRD")//指定代理
                    {
                        CurrentForm.DataSources.UserDataSources.Item("CardName").Value = pVal.SelectedObjects.GetValue("CardName", 0).ToString();
                    }
                }
            }
        }
        #endregion
        #region Method
        /// <summary>
        /// 判断是否是账单
        /// </summary>
        /// <param name="ItemUID"></param>
        private void IsBill(string ItemUID)
        {
            SAPbouiCOM.OptionBtn oitem = CurrentForm.Items.Item(ItemUID).Specific;
            if (oitem.Selected)
            {
                AddBill = false;
                if (ItemUID == "rdobill")
                {
                    SAPBoAddon.B1Assistant.Item.SetEnabled(CurrentForm, "BillNo", true);
                    SAPbouiCOM.EditText oedit = CurrentForm.Items.Item("BillNo").Specific;
                    oedit.Active = true;
                    SAPBoAddon.B1Assistant.Item.SetEnabled(CurrentForm, "AddBill", true);
                    SAPBoAddon.B1Assistant.Item.SetEnabled(CurrentForm, "CardName", false);
                    SAPBoAddon.B1Assistant.Item.SetEnabled(CurrentForm, "StartDate", false);
                    SAPBoAddon.B1Assistant.Item.SetEnabled(CurrentForm, "EndDate", false);
                    SAPBoAddon.B1Assistant.Item.SetEnabled(CurrentForm, "Currency", false);
                    SAPBoAddon.B1Assistant.Item.SetEnabled(CurrentForm, "rdooBill", false);
                    SAPBoAddon.B1Assistant.Item.SetEnabled(CurrentForm, "rdooFee", false);
                    SAPBoAddon.B1Assistant.Item.SetEnabled(CurrentForm, "rdooAll", false);
                }
                else
                {
                    SAPBoAddon.B1Assistant.Item.SetEnabled(CurrentForm, "CardName", true);
                    SAPBoAddon.B1Assistant.Item.SetEnabled(CurrentForm, "StartDate", true);
                    SAPBoAddon.B1Assistant.Item.SetEnabled(CurrentForm, "EndDate", true);
                    SAPbouiCOM.EditText oedit = CurrentForm.Items.Item("CardName").Specific;
                    oedit.Active = true;

                    SAPBoAddon.B1Assistant.Item.SetEnabled(CurrentForm, "BillNo", false);
                    SAPBoAddon.B1Assistant.Item.SetEnabled(CurrentForm, "AddBill", false);

                    SAPBoAddon.B1Assistant.Item.SetEnabled(CurrentForm, "Currency", true);
                    SAPBoAddon.B1Assistant.Item.SetEnabled(CurrentForm, "rdooBill", true);
                    SAPBoAddon.B1Assistant.Item.SetEnabled(CurrentForm, "rdooFee", true);
                    SAPBoAddon.B1Assistant.Item.SetEnabled(CurrentForm, "rdooAll", true);
                }
            }
        }
        /// <summary>
        /// 计算合计数
        /// </summary>
        /// <param name="row"></param>
        private void Sum(int row)
        {
            SAPbouiCOM.Grid oGrid = CurrentFormEx.Items.Item("Grid").Specific;
            decimal Amount = Convert.ToDecimal(oGrid.DataTable.GetValue("Total", row));
            //string Currency = oGrid.DataTable.GetValue("Currency", row).ToString().Trim();
            //decimal Rate = Convert.ToDecimal(oGrid.DataTable.GetValue("Rate", row).ToString().Trim());
            //Rate = Rate == 0 ? 1 : Rate;
            string sum = CurrentForm.DataSources.UserDataSources.Item("sum").Value;
            if (string.IsNullOrEmpty(sum))
                sum = "0";
            if (oGrid.DataTable.GetValue("Choose", row) == "Y")
                sum = (Convert.ToDecimal(sum) + Amount).ToString();
            else
                sum = (Convert.ToDecimal(sum) - Amount).ToString();
            CurrentForm.DataSources.UserDataSources.Item("sum").Value = sum;
        }
        /// <summary>
        /// 查找
        /// </summary>
        private void Find()
        {
            string SQL = string.Empty;
            string CardName = string.Empty;
            string Currency = string.Empty;
            string StartDate, EndDate;
            string IsFee = "A";
            string DraftKey = string.Empty;
            string SourceXml = string.Empty;

            CardName = SAPBoAddon.B1Assistant.Item.GetValue(CurrentForm, "CardName").ToString().Trim();
            if (SAPBoAddon.B1Assistant.Item.GetValue(CurrentForm, "StartDate").ToString().Trim() == "")
                StartDate = "";
            else
                StartDate = SAPBoAddon.B1Assistant.Time.GetDateTime(SAPBoAddon.B1Assistant.Item.GetValue(CurrentForm, "StartDate").ToString().Trim(), "0").ToString();
            if (SAPBoAddon.B1Assistant.Item.GetValue(CurrentForm, "EndDate").ToString().Trim() == "")
                EndDate = "";
            else
                EndDate = SAPBoAddon.B1Assistant.Time.GetDateTime(SAPBoAddon.B1Assistant.Item.GetValue(CurrentForm, "EndDate").ToString().Trim(), "0").ToString();
            Currency = SAPBoAddon.B1Assistant.Item.GetValue(CurrentForm, "Currency").ToString().Trim();
            if (SAPBoAddon.B1Assistant.Item.GetValue(CurrentForm, "rdooBill").ToString().Trim() == "Y") IsFee = "B";
            if (SAPBoAddon.B1Assistant.Item.GetValue(CurrentForm, "rdooFee").ToString().Trim() == "Y") IsFee = "F";
            if (SAPBoAddon.B1Assistant.Item.GetValue(CurrentForm, "rdooAll").ToString().Trim() == "Y") IsFee = "A";
            DraftKey = SAPBoAddon.B1Assistant.Item.GetValue(CurrentForm, "BillNo").ToString().Trim();
            CurrentForm.DataSources.UserDataSources.Item("sum").Value = "0";

            SAPbouiCOM.Grid oGrid = CurrentForm.Items.Item("Grid").Specific;
            if (AddBill)
            {
                SourceXml = oGrid.DataTable.SerializeAsXML(SAPbouiCOM.BoDataTableXmlSelect.dxs_DataOnly);
            }
            #region DataTable
            SAPbouiCOM.DataTable dt;
            try
            {
                dt = CurrentForm.DataSources.DataTables.Add("dt");
            }
            catch
            {
                dt = CurrentForm.DataSources.DataTables.Item("dt");
                dt.Clear();
                oBillDraft = null;
            }
            #endregion
            if (CurrentForm.DataSources.UserDataSources.Item("IsBill").Value == "1" || AddBill)
            {
                #region 账单查询
                if (Type == Bo.OrderType.ARInvoice)
                    SQL = "EXEC AVA_OpenBill 'AR','{0}','{1}','{2}','{3}','{4}'";
                else
                    SQL = "EXEC AVA_OpenBill 'AP','{0}','{1}','{2}','{3}','{4}'";
                #endregion
                dt.ExecuteQuery(string.Format(SQL, CardName, StartDate, EndDate, Currency, IsFee));
            }
            else
            {
                #region 草稿查询
                if (Type == Bo.OrderType.ARInvoice)
                    SQL = "EXEC AVA_OpenBill 'DR','无意义','2012-12-12','2012-12-12','','{0}','{1}'";
                else
                    SQL = "EXEC AVA_OpenBill 'DP','无意义','2012-12-12','2012-12-12','','{0}','{1}'";
                #endregion
                dt.ExecuteQuery(string.Format(SQL, IsFee, DraftKey));
            }
            if (AddBill)
            {
                System.Xml.XmlDocument Source = new System.Xml.XmlDocument();
                Source.LoadXml(SourceXml);
                System.Xml.XmlDocument Target = new System.Xml.XmlDocument();
                string TargetXml = dt.SerializeAsXML(SAPbouiCOM.BoDataTableXmlSelect.dxs_DataOnly);
                Target.LoadXml(TargetXml);
                foreach (System.Xml.XmlNode node in Target.SelectNodes("//Rows"))
                {
                    Source.SelectSingleNode("//Rows").InnerXml += node.InnerXml.ToString();
                }
                dt.LoadSerializedXML(SAPbouiCOM.BoDataTableXmlSelect.dxs_DataOnly, Source.OuterXml);
            }
            oGrid.DataTable = dt;
            if (dt.Columns.Count > 0)
            {
                oGrid.Columns.Item(0).Type = SAPbouiCOM.BoGridColumnType.gct_CheckBox;
                for (int i = 1; i < oGrid.Columns.Count; i++)
                {
                    oGrid.Columns.Item(i).Editable = false;
                }
            }
            //#region 设置已对账的行不可编辑 by WangPeng 2012年9月20日 17:25:44
            //if (CurrentForm.DataSources.UserDataSources.Item("IsBill").Value == "1")
            //{
            //    int Row_Dt = 0;
            //    for (int Row = 0; Row < oGrid.Rows.Count; Row++)
            //    {
            //        Row_Dt = oGrid.GetDataTableRowIndex(Row);
            //        if (oGrid.DataTable.GetValue("Choose", Row_Dt) == "Y")
            //        {
            //            oGrid.CommonSetting.SetRowEditable(Row + 1, false);
            //        }
            //    }
            //}
            //#endregion
            if (CurrentForm.DataSources.UserDataSources.Item("IsBill").Value == "2")
            {
                for (int i = 0; i < oGrid.Rows.Count; i++)
                {
                    if (oGrid.DataTable.GetValue("Choose", i) == "Y")
                    {
                        UIChanged("Grid", "Choose", i, true);
                    }
                }
            }
        }
        /// <summary>
        /// UI变化
        /// </summary>
        /// <param name="ItemUID"></param>
        /// <param name="ColUID"></param>
        /// <param name="row"></param>
        private void UIChanged(string ItemUID, string ColUID = null, int row = -1, bool IsModify = false)
        {
            #region varialbe
            string CardCode = string.Empty;
            string BaseType = string.Empty;
            int BaseEntry, BaseLine;
            double Rate = -1;
            string OrderType = string.Empty;
            #endregion
            SAPbouiCOM.Grid oGrid = CurrentFormEx.Items.Item(ItemUID).Specific;
            if (oGrid.Columns.Item(ColUID).Type == SAPbouiCOM.BoGridColumnType.gct_CheckBox)
            {
                row = oGrid.GetDataTableRowIndex(row);
                CardCode = oGrid.DataTable.GetValue("CardCode", row);
                string IsChecked = oGrid.DataTable.GetValue("Choose", row);
                #region 判断是否是同一结算单位
                if (oBillDraft == null)
                {
                    oBillDraft = new BillDraft();
                }
                else
                {
                    if (oBillDraft.CardCode != CardCode)
                    {
                        oGrid.DataTable.SetValue("Choose", row, "N");
                        SBOApp.MessageBox("请选择同一结算单位.");
                        CurrentForm.Refresh();
                        return;
                    }
                }
                #endregion
                if (IsModify && oBillDraft.IsModify == false)
                {
                    oBillDraft.IsModify = true;
                    oBillDraft.DraftKey = Convert.ToInt32(oGrid.DataTable.GetValue("DocEntry", row));
                    oBillDraft.CardName = oGrid.DataTable.GetValue("CardName", row);
                }
                oBillDraft.CardCode = CardCode;
                oBillDraft.DocDate = DateTime.Now;
                if (Type == Bo.OrderType.ARInvoice)
                    oBillDraft.OrderType = Bo.OrderType.ARInvoice;
                else
                    oBillDraft.OrderType = Bo.OrderType.APInvoice;

                BaseType = oGrid.DataTable.GetValue("BaseType", row).ToString();
                BaseEntry = Convert.ToInt32(oGrid.DataTable.GetValue("BaseEntry", row).ToString());
                BaseLine = Convert.ToInt32(oGrid.DataTable.GetValue("BaseLine", row).ToString());
                oBillDraft.Currency = CurrentForm.DataSources.UserDataSources.Item("DocCurr").Value.Trim();
                Rate = Convert.ToDouble((string.IsNullOrEmpty(CurrentForm.DataSources.UserDataSources.Item("DocRate").Value.Trim()) ? "1" : CurrentForm.DataSources.UserDataSources.Item("DocRate").Value.Trim()));
                oBillDraft.Rate = Rate;
                OrderType = oGrid.DataTable.GetValue("OrderType", row);

                if (oGrid.DataTable.GetValue("Choose", row) == "Y")
                {
                    #region 添加行
                    if (OrderType == "费用")
                    {
                        #region 基于订单
                        BillDraftLine line = oBillDraft.Lines.Add();
                        line.BaseType = int.Parse(BaseType);
                        line.BaseEntry = BaseEntry;
                        line.BaseLine = BaseLine;
                        SAPbobsCOM.Recordset rs = SBOCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
                        if (Type == Bo.OrderType.ARInvoice)
                        {
                            rs.DoQuery("SELECT LineNum,Currency,Rate FROM RDR1 Where ObjType = '" + BaseType + "' And DocEntry = '" + BaseEntry + "' And LineNum = " + BaseLine);
                        }
                        else
                        {
                            rs.DoQuery("SELECT LineNum,Currency,Rate FROM POR1 Where ObjType = '" + BaseType + "' And DocEntry = '" + BaseEntry + "' And LineNum = " + BaseLine);
                        }
                        line.Currency = rs.Fields.Item("Currency").Value;
                        line.Rate = rs.Fields.Item("Rate").Value;
                        #endregion
                    }
                    else
                    {
                        #region 基于交货
                        SAPbobsCOM.Recordset rs = SBOCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
                        if (Type == Bo.OrderType.ARInvoice)
                        {
                            if (BaseType == "15")
                                rs.DoQuery("SELECT LineNum,Currency,Rate FROM DLN1 Where ObjType = '" + BaseType + "' And DocEntry = '" + BaseEntry + "'");
                        }
                        else
                        {
                            if (BaseType == "20")
                                rs.DoQuery("SELECT LineNum,Currency,Rate FROM PDN1 Where ObjType = '" + BaseType + "' And DocEntry = '" + BaseEntry + "'");
                        }

                        for (int i = 0; i < rs.RecordCount; i++)
                        {
                            BillDraftLine line = oBillDraft.Lines.Add();
                            line.BaseType = int.Parse(BaseType);
                            line.BaseEntry = BaseEntry;
                            line.BaseLine = rs.Fields.Item("LineNum").Value;
                            line.Currency = rs.Fields.Item("Currency").Value;
                            line.Rate = rs.Fields.Item("Rate").Value;
                            rs.MoveNext();
                        }
                        System.Runtime.InteropServices.Marshal.FinalReleaseComObject(rs);
                        #endregion
                    }
                    #endregion
                }
                else
                {
                    #region 移除选中项
                    if (OrderType == "费用")
                    {
                        oBillDraft.Lines.DeleteDraftLine(int.Parse(BaseType), BaseEntry, BaseLine);
                    }
                    else
                    {
                        SAPbobsCOM.Recordset rs = SBOCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
                        if (Type == Bo.OrderType.ARInvoice)
                        {
                            if (BaseType == "15")
                                rs.DoQuery("SELECT LineNum,Rate FROM DLN1 Where ObjType = '" + BaseType + "' And DocEntry = '" + BaseEntry + "'");
                            else
                                rs.DoQuery("SELECT LineNum,Rate FROM RDR1 Where ObjType = '" + BaseType + "' And DocEntry = '" + BaseEntry + "'");
                        }
                        else
                        {
                            if (BaseType == "20")
                                rs.DoQuery("SELECT LineNum,Rate FROM PDN1 Where ObjType = '" + BaseType + "' And DocEntry = '" + BaseEntry + "'");
                            else
                                rs.DoQuery("SELECT LineNum,Rate FROM POR1 Where ObjType = '" + BaseType + "' And DocEntry = '" + BaseEntry + "'");
                        }
                        for (int i = 0; i < rs.RecordCount; i++)
                        {
                            oBillDraft.Lines.DeleteDraftLine(int.Parse(BaseType), BaseEntry, rs.Fields.Item("LineNum").Value);
                            rs.MoveNext();
                        }
                    }
                    #endregion
                }
                Sum(row);
            }

        }
        private void CreateDraft(ref bool BubbleEvent)
        {
            CreateBillDraft BillDraft = new CreateBillDraft();
            BillDraft.Draft = this.oBillDraft;
            BillDraft.SBOCompany = SBOCompany;
            try
            {
                var result = BillDraft.HandleDraft();
                if (result.Value)
                {
                    AddBill = false;
                    oBillDraft = null;
                    SBOApp.MessageBox(result.Message);
                    CurrentForm.Items.Item("Find").Click(SAPbouiCOM.BoCellClickType.ct_Regular);
                    CurrentForm.DataSources.UserDataSources.Item("sum").Value = "0";
                }
                else
                {
                    SBOApp.MessageBox(result.Message);
                    BubbleEvent = false;
                }
            }
            catch (Exception ex)
            {
                BubbleEvent = false;
                SBOApp.MessageBox(ex.Message);
            }

        }
        /// <summary>
        /// 反选 
        /// </summary>
        private void ChooseAbOrder()
        {
            SAPbouiCOM.Grid oGrid = CurrentForm.Items.Item("Grid").Specific;
            for (int i = 0; i < oGrid.Rows.Count; i++)
            {
                if (oGrid.DataTable.GetValue("Choose", i) == "N")
                {
                    oGrid.DataTable.SetValue("Choose", i, "Y");
                    UIChanged("Grid", "Choose", i);
                    if (CurrentForm.Mode != SAPbouiCOM.BoFormMode.fm_UPDATE_MODE) CurrentForm.Mode = SAPbouiCOM.BoFormMode.fm_UPDATE_MODE;
                }
                else
                {
                    oGrid.DataTable.SetValue("Choose", i, "N");
                    UIChanged("Grid", "Choose", i);
                    if (CurrentForm.Mode != SAPbouiCOM.BoFormMode.fm_UPDATE_MODE) CurrentForm.Mode = SAPbouiCOM.BoFormMode.fm_UPDATE_MODE;
                }
            }
        }
        /// <summary>
        /// 选择
        /// </summary>
        /// <param name="IsAll"></param>
        private void ChooseOrder(bool IsAll)
        {
            SAPbouiCOM.Grid oGrid = CurrentForm.Items.Item("Grid").Specific;
            for (int i = 0; i < oGrid.Rows.Count; i++)
            {
                if (IsAll == true)
                    if (oGrid.DataTable.GetValue("Choose", i) == "N")
                    {
                        oGrid.DataTable.SetValue("Choose", i, "Y");
                        UIChanged("Grid", "Choose", i);
                        if (CurrentForm.Mode != SAPbouiCOM.BoFormMode.fm_UPDATE_MODE) CurrentForm.Mode = SAPbouiCOM.BoFormMode.fm_UPDATE_MODE;
                    }
                if (IsAll == false)
                    if (oGrid.DataTable.GetValue("Choose", i) == "Y")
                    {
                        oGrid.DataTable.SetValue("Choose", i, "N");
                        UIChanged("Grid", "Choose", i);
                        if (CurrentForm.Mode != SAPbouiCOM.BoFormMode.fm_UPDATE_MODE) CurrentForm.Mode = SAPbouiCOM.BoFormMode.fm_UPDATE_MODE;
                    }
            }
        }
        #endregion
    }
}
